package com.zdsoft.blp.zongbuju.shouye.linliquan.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.zdsoft.blp.R;
import com.zdsoft.blp.zongbuju.shouye.linliquan.entity.LinLi;

import java.util.List;

/**
 * Created by Administrator on 2016/8/31.
 */
public class ZZLYadapter extends BaseAdapter{
    private List<LinLi> list;
    private LayoutInflater inflater;
    private Context context;

    public ZZLYadapter(List<LinLi> list, Context context) {
        this.list = list;
        this.context = context;
        inflater=LayoutInflater.from(context);
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        if (convertView==null){
            convertView=inflater.inflate(R.layout.linli_zizhulvyou_item,null);
            holder=new ViewHolder();
            holder.lvyou_lianxiren= (TextView) convertView.findViewById(R.id.lvyou_lianxiren);
            holder.lvyou_didian= (TextView) convertView.findViewById(R.id.lvyou_didian);
            holder.lvyou_dianhua= (TextView) convertView.findViewById(R.id.lvyou_dianhua);
            holder.tv_delete= (TextView) convertView.findViewById(R.id.tv_delete);

            holder.lvyou_image= (ImageView) convertView.findViewById(R.id.lvyou_image);
            holder.iv_shenhe= (ImageView) convertView.findViewById(R.id.iv_shenhe);
            holder.ll_shenhe= (LinearLayout) convertView.findViewById(R.id.ll_shenhe);

            convertView.setTag(holder);
        }else {
            holder= (ViewHolder) convertView.getTag();
        }

        LinLi user=list.get(position);
       if (user.getCode()==2){
           holder.ll_shenhe.setVisibility(View.VISIBLE);
           switch (user.getApprovedResult()){
               case -1:
                   Picasso.with(context).load(R.drawable.shz).into(holder.iv_shenhe);
                   break;
               case 0:
                   Picasso.with(context).load(R.drawable.shwtg).into(holder.iv_shenhe);
                   break;
               case 1:
                   Picasso.with(context).load(R.drawable.shtg).into(holder.iv_shenhe);
                   break;
           }
       }else {
           holder.ll_shenhe.setVisibility(View.GONE);
       }
        holder.lvyou_lianxiren.setText(user.getUsername());
        holder.lvyou_didian.setText(user.getTitle());
        holder.lvyou_dianhua.setText(user.getDianhua());
        if (!"".equals(user.getPicPath())){
            Picasso.with(context).load(user.getPicPath()).error(R.drawable.no_pic).placeholder(R.drawable.loading).into(holder.lvyou_image);

        }

        return convertView;
    }
    class ViewHolder{
        TextView lvyou_didian,lvyou_lianxiren,lvyou_dianhua,tv_delete;
        ImageView lvyou_image,iv_shenhe;
        LinearLayout ll_shenhe;

    }
    public List<LinLi> setListData(List<LinLi> list){
        return this.list=list;
    }
}
